package com.xy.mainp.huaban.widget;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.xy.img.GlideUtil;
import com.xy.mainp.R;
import com.xy.mainp.databinding.ViewMsgImgItemBinding;
import com.xy.mainp.model.huaban.ImgEntity;

/**
 * Created by John on 2016/11/15.
 */

public class ItemImgView extends FrameLayout {

    private ViewMsgImgItemBinding binding;

    public ItemImgView(Context context) {
        this(context,null);
    }

    public ItemImgView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public ItemImgView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getContext()),R.layout.view_msg_img_item, this, true);
    }

    public void setData(ImgEntity imgEntity){
        binding.setImgEntity(imgEntity);
        binding.ivMsg.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,Integer.valueOf(imgEntity.getImgHeight())* 3));
        GlideUtil.loadImage(imgEntity.getImgUrl(),binding.ivMsg);
        GlideUtil.loadImageR(imgEntity.getAuthorImg(),binding.imgAuthorHeader,R.drawable.usr_headerbox_cev_img);
    }

    public ImageView getImg(){
        return binding.ivMsg;
    }
}
